import { Controller, Get, Post, Body, Patch, Param, Delete, UseInterceptors, UploadedFile, Query } from '@nestjs/common';
import { BannerService } from './banner.service';
import { CreateBannerDto } from './dto/create-banner.dto';
import { UpdateBannerDto } from './dto/update-banner.dto';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';

@Controller('banner')
export class BannerController {
  constructor(private readonly bannerService: BannerService) { }

  @Post()
  @UseInterceptors(FileInterceptor('banner'))
  create(@Body() createBannerDto: CreateBannerDto, @UploadedFile() file: any) {
    createBannerDto.img_src = file.filename
    return this.bannerService.create(createBannerDto);
  }

  @Get()
  async findAll(@Query() query: any) {
    return {
      code: 200,
      message: "find all banner success",
      data: await this.bannerService.findAll(query)
    }
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.bannerService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateBannerDto: UpdateBannerDto) {
    return this.bannerService.update(+id, updateBannerDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.bannerService.remove(+id);
  }
}
